<template>
  <el-submenu
    v-if="menu.list && menu.list.length >= 1"
    :index="menu.menuId + ''"
    :popper-class="'site-sidebar--' + sidebarLayoutSkin + '-popper'">
    <template slot="title">
      <icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
      <span>{{ menu.name }}</span>
    </template>
    <sub-menu
      v-for="item in menu.list"
      :key="item.menuId"
      :menu="item"
      :dynamicMenuRoutes="dynamicMenuRoutesList">
    </sub-menu>
  </el-submenu>
  <el-menu-item v-else-if="(menu.hidden=='0')" :index="menu.menuId + ''" @click="gotoRouteHandle(menu)" class="main-sub-menu" >
    <icon-svg  :name="menu.icon || ''" class="site-sidebar__menu-icon" ></icon-svg> 
    <span :class="menu.pid==118?'info-sub-menu':''">
      {{ menu.name}}
      <el-tooltip v-if="menu.pid==118&&menu.notes" class="info">
      <div slot="content" v-html="menu.notes"></div>
      <b >i</b>
      </el-tooltip>
      </span>
  </el-menu-item>
</template>

<script> 
  // import SubMenu from './main-sidebar-sub-menu'
  export default {
    name: 'sub-menu',
    props: {
      menu: {
        type: Object,
        required: true
      },
      dynamicMenuRoutes: {
        type: Array,
        required: true
      },
      'defaultActive':{ 
          default: ''
      }
      
    },
    watch: {
      dynamicMenuRoutes (val) {
        this.dynamicMenuRoutesList = val
      }
    },
    data () {
      return {
        dynamicMenuRoutesList: this.dynamicMenuRoutes
      }
    },
    components: {
      // SubMenu
    },
    computed: {
      sidebarLayoutSkin: {
        get () { return this.$store.state.common.sidebarLayoutSkin }
      },
      pathParm:{
        get () { return this.$store.state.common.pathParm },
        set (val) { this.$store.commit('common/updatePathParm', val) }
      }
    }, 
    methods: {
      // 通过menuId与动态(菜单)路由进行匹配跳转至指定路由
      gotoRouteHandle (menu) {
        var route = this.dynamicMenuRoutesList.filter(item => item.meta.menuId === menu.menuId)
        if (route.length >= 1) {
          var parm = this.pathParm;
          parm[route[0].name] = "";
          this.pathParm = parm;
          this.$router.push({ name: route[0].name, query:{menuid:route[0].meta.menuId} })
          this.savemenuClick(route[0])
        }
      },
      savemenuClick(route){
        this.$http({
          url: this.$http.adornUrl('/sys/log/savemenuClick'),
          method: 'post',
          data: this.$http.adornData({
            'method':route.name+'^'+route.meta.title
          })
        }).then(({data}) => {
          if (data && data.code === 0) {

          } else {
          }
        })
      }
    }
  }
</script>
<style lang="less" scoped>
.info-sub-menu{
  position: relative;
  .info{
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: -20px;
    color: rgb(157 154 154);
    width: 14px;
    height: 14px;
    font-size: 12px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px rgb(157 154 154) solid;
    font-weight: normal;

  }
}
</style>